<!-- 公司名片 信息管理 -->
<template>
  <div class='company_detail'>
    <div class="detail_title">
      <div class="detail_title_warp">
        <span>{{info.companyName}}</span>
        <span class="houses_edit" @click="checkFun">查看</span>
        <span class="houses_edit" @click="changeCompany" v-if="unlocking('0212010201') && isEdit">修改</span>
      </div>
    </div>
    <Tabs ref="nav" type="card" v-model="showTab" :animated="false">
      <TabPane label="公司简介" name="profile">
        <company-profile ref="companyProfile" />
      </TabPane>
      <TabPane label="公司服务" name="service">
        <company-server ref="companyServer" />
      </TabPane>
      <div slot="extra">
        <Button @click="preview" type="primary" >预览</Button>注意：请先保存已编辑的内容，再进行预览
      </div>
    </Tabs>
    <add-company ref="addCompany" @success='onSuccess' />
    <preview-page ref="previewPage" />
    <check-modal ref="check" />

  </div>
</template>

<script>
  import companyApi from '@/biz/backStage/companyCard'
  import companyServer from './components/companyService'
  import companyProfile from './components/companyProfile'
  import addCompany from './components/addCompany'
  import previewPage from './components/proview'
  import checkModal from './components/checkModal'

  export default {
    components:{ companyServer, companyProfile, addCompany, previewPage, checkModal },
    data() {
      return {
        showTab:'profile',
        isEdit: this.$route.query.isEdit == 'view'?false:true,
        info:{}
      };
    },
    methods: {
     //新建公司
      changeCompany(){
        let data = {
          title:'编辑公司',
          flag:'edit',
          ...this.info
        }
        this.$refs.addCompany.show(data)
      },
      init(){
        let params={
          id: this.$route.query.companyId
        }
        companyApi.getByCompanyId(params).then(res => {
          if (res) {
            this.info = res
            this.$refs.companyProfile.proFileInit(res)
          } 
        })
      },
      onSuccess(){
        this.init()
      },
      preview(){
        console.log('preview')
        this.$refs.previewPage.init({id:'123131'})
      },
      checkFun() {
        let data = {
          title:'查看公司',
          ...this.info
        }
        this.$refs.check.show(data)
      },
    },
    mounted() {
     this.init()
     if (this.$route.name == 'companyDetail') {
        window.onbeforeunload = function (e) {
          return ''
        }
      }
    },
    destroyed () {
      window.onbeforeunload = null
    },
  }
</script>
<style lang='scss' scoped>
  .company_detail {
    padding: 15px;
  }
  .detail_title {
      font-size: 26px;
      line-height: 30px;
      padding: 20px 10px;
      display: flex;
      justify-content: space-between;

      .detail_title_warp {
        .houses_edit {
          margin-left: 10px;
          font-size: 15px;
          color: #2d8cf0;
          cursor: pointer;
        }
      }
    }
</style>